home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume20 / pcomm1.2 / part05 < prev    next >
Encoding:
Internet Message Format  |  1989-10-25  |  59.4 KB

  1. Subject:  v20i071:  Pcomm telecommunication package, Part05/08
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: fthood!egray
  7. Posting-number: Volume 20, Issue 71
  8. Archive-name: pcomm1.2/part05
  9.  
  10. #! /bin/sh
  11. # This is a shell archive, meaning:
  12. # 1. Remove everything above the #! /bin/sh line.
  13. # 2. Save the resulting text in a file.
  14. # 3. Execute the file with /bin/sh (not csh) to create:
  15. #    m_lib.c
  16. #    macro.c
  17. #    main.c
  18. #    matches.c
  19. #    misc.h
  20. #    modem.h
  21. #    modem_break.c
  22. #    n_shell.c
  23. #    p_lib.c
  24. #    param.h
  25. #    passthru.c
  26. #    pexit.c
  27. #    port.c
  28. export PATH; PATH=/bin:/usr/bin:$PATH
  29. echo shar: "extracting 'm_lib.c'" '(9951 characters)'
  30. if test -f 'm_lib.c'
  31. then
  32.     echo shar: "will not over-write existing file 'm_lib.c'"
  33. else
  34. sed 's/^X//' << \SHAR_EOF > 'm_lib.c'
  35. X/*
  36. X * Routines to manipulate the pcomm.modem file
  37. X */
  38. X
  39. X#include <stdio.h>
  40. X#include "modem.h"
  41. X
  42. X/*
  43. X * Read the modem/TTY database file.  Returns a pointer to a static area
  44. X * containing the MODEM structure.  All modem entries and all TTY entries
  45. X * are created regardless of the number of physical entries in the file.
  46. X */
  47. X
  48. Xstruct MODEM *
  49. Xread_modem(extra)
  50. Xchar *extra;
  51. X{
  52. X    extern char *null_ptr;
  53. X    FILE *fp, *my_fopen();
  54. X    int i, tty, mod, line, oops, m_line, start, stop;
  55. X    char *str_dup(), buf[200], message[80], token[40], *str_tok(), *str;
  56. X    char *temp_token, *t_sep, *m_sep, *m_letter, *findfile();
  57. X    static struct MODEM m;
  58. X    void error_win();
  59. X
  60. X    if ((m.m_path = findfile(extra, "pcomm.modem")) == NULL)
  61. X        error_win(1, "Support file \"pcomm.modem\" is missing", "or no read permission");
  62. X
  63. X    if (!(fp = my_fopen(m.m_path, "r"))) {
  64. X        sprintf(buf, "\"%s\" for read", m.m_path);
  65. X        error_win(1, "Can't open modem/TTY file", buf);
  66. X    }
  67. X
  68. X    t_sep = ";;\n";
  69. X    m_sep = ";;;;\n;;;;;;\n;;;\n";
  70. X    m_letter = "abc";
  71. X    oops = 0;
  72. X    tty = 0;
  73. X    mod = 0;
  74. X    line = 0;
  75. X    m_line = 0;
  76. X    while (fgets(buf, 200, fp) != NULL) {
  77. X        line++;
  78. X        if (tty >= NUM_TTY || mod >= NUM_MODEM)
  79. X            break;
  80. X                    /* get the token */
  81. X        if (!(temp_token = str_tok(buf, '='))) {
  82. X            sprintf(message, "is missing a token at line %d", line);
  83. X            oops++;
  84. X            break;
  85. X        }
  86. X        if (*temp_token != 'T' && *temp_token != 'M') {
  87. X            sprintf(message, "is corrupted at line %d", line);
  88. X            oops++;
  89. X            break;
  90. X        }
  91. X                    /* the TTY database */
  92. X        if (*temp_token == 'T') {
  93. X            /*
  94. X             * This is similar to the "real" strtok() command
  95. X             * but this one returns a pointer to NULL on a missing
  96. X             * token.  Note the use of the field separator
  97. X             * array.
  98. X             */
  99. X            for (i=0; i<3; i++) {
  100. X                if (!(str = str_tok((char *) NULL, t_sep[i]))) {
  101. X                    sprintf(message, "is missing a parameter at line %d", line);
  102. X                    oops++;
  103. X                    break;
  104. X                }
  105. X                switch (i) {
  106. X                    case 0:
  107. X                        m.tty[tty] = str_dup(str);
  108. X                        break;
  109. X                    case 1:
  110. X                        m.tname[tty] = str_dup(str);
  111. X                        break;
  112. X                    case 2:
  113. X                        m.init_sp[tty] = atoi(str);
  114. X                        break;
  115. X                }
  116. X            }
  117. X            if (oops)
  118. X                break;
  119. X                    /* sanity checking */
  120. X            sprintf(token, "TTY_%d", tty+1);
  121. X            if (strcmp(token, temp_token)) {
  122. X                sprintf(message, "is corrupted at line %d", line);
  123. X                oops++;
  124. X                break;
  125. X            }
  126. X            tty++;
  127. X            continue;
  128. X        }
  129. X                    /* the modem database */
  130. X        else {
  131. X            sprintf(token, "MODEM_%d%c", mod+1, m_letter[m_line]);
  132. X            if (strcmp(token, temp_token)) {
  133. X                sprintf(message, "is corrupted at line %d", line);
  134. X                oops++;
  135. X                break;
  136. X            }
  137. X            /*
  138. X             * There are three lines to the modem database.  They
  139. X             * are distinguished by the letters a, b, and, c
  140. X             * appended to the entry number.
  141. X             */
  142. X            switch (m_line) {
  143. X                case 0:
  144. X                    start = 0;
  145. X                    stop = 5;
  146. X                    break;
  147. X                case 1:
  148. X                    start = 5;
  149. X                    stop = 12;
  150. X                    break;
  151. X                case 2:
  152. X                    start = 12;
  153. X                    stop = 16;
  154. X                    break;
  155. X            }
  156. X            for (i=start; i<stop; i++) {
  157. X                if (!(str = str_tok((char *) NULL, m_sep[i]))) {
  158. X                    sprintf(message, "is missing a parameter at line %d", line);
  159. X                    oops++;
  160. X                    break;
  161. X                }
  162. X                switch (i) {
  163. X                    case 0:
  164. X                        m.mname[mod] = str_dup(str);
  165. X                        break;
  166. X                    case 1:
  167. X                        m.init[mod] = str_dup(str);
  168. X                        break;
  169. X                    case 2:
  170. X                        m.dial[mod] = str_dup(str);
  171. X                        break;
  172. X                    case 3:
  173. X                        m.suffix[mod] = str_dup(str);
  174. X                        break;
  175. X                    case 4:
  176. X                        m.hang_up[mod] = str_dup(str);
  177. X                        break;
  178. X                    case 5:
  179. X                        m.auto_baud[mod] = *str;
  180. X                        break;
  181. X                    case 6:
  182. X                        m.con_3[mod] = str_dup(str);
  183. X                        break;
  184. X                    case 7:
  185. X                        m.con_12[mod] = str_dup(str);
  186. X                        break;
  187. X                    case 8:
  188. X                        m.con_24[mod] = str_dup(str);
  189. X                        break;
  190. X                    case 9:
  191. X                        m.con_48[mod] = str_dup(str);
  192. X                        break;
  193. X                    case 10:
  194. X                        m.con_96[mod] = str_dup(str);
  195. X                        break;
  196. X                    case 11:
  197. X                        m.con_192[mod] = str_dup(str);
  198. X                        break;
  199. X                    case 12:
  200. X                        m.no_con1[mod] = str_dup(str);
  201. X                        break;
  202. X                    case 13:
  203. X                        m.no_con2[mod] = str_dup(str);
  204. X                        break;
  205. X                    case 14:
  206. X                        m.no_con3[mod] = str_dup(str);
  207. X                        break;
  208. X                    case 15:
  209. X                        m.no_con4[mod] = str_dup(str);
  210. X                        break;
  211. X                }
  212. X            }
  213. X            if (oops)
  214. X                break;
  215. X            m_line++;
  216. X            if (m_line >= 3) {
  217. X                m_line = 0;
  218. X                mod++;
  219. X            }
  220. X        }
  221. X    }
  222. X    fclose(fp);
  223. X
  224. X    if (oops) {
  225. X        sprintf(buf, "Modem/TTY database file \"%s\"", m.m_path);
  226. X        error_win(1, buf, message);
  227. X    }
  228. X    m.t_entries = tty;
  229. X    m.m_entries = mod;
  230. X    m.t_cur = -1;
  231. X    m.m_cur = -1;
  232. X                    /* if empty database */
  233. X    if (!tty) {
  234. X        sprintf(buf, "Modem/TTY database file \"%s\"", m.m_path);
  235. X        error_win(0, buf, "has no TTY data");
  236. X    }
  237. X    if (!mod) {
  238. X        sprintf(buf, "Modem/TTY database file \"%s\"", m.m_path);
  239. X        error_win(0, buf, "has no modem data");
  240. X    }
  241. X                    /* fill in the rest */
  242. X    for (; tty<NUM_TTY; tty++) {
  243. X        m.tty[tty] = null_ptr;
  244. X        m.tname[tty] = null_ptr;
  245. X        m.init_sp[tty] = 0;
  246. X    }
  247. X    for (; mod<NUM_MODEM; mod++) {
  248. X        m.mname[mod] = null_ptr;
  249. X        m.init[mod] = null_ptr;
  250. X        m.dial[mod] = null_ptr;
  251. X        m.suffix[mod] = null_ptr;
  252. X        m.hang_up[mod] = null_ptr;
  253. X
  254. X        m.auto_baud[mod] = 'Y';
  255. X        m.con_3[mod] = null_ptr;
  256. X        m.con_12[mod] = null_ptr;
  257. X        m.con_24[mod] = null_ptr;
  258. X        m.con_48[mod] = null_ptr;
  259. X        m.con_96[mod] = null_ptr;
  260. X        m.con_192[mod] = null_ptr;
  261. X
  262. X        m.no_con1[mod] = null_ptr;
  263. X        m.no_con2[mod] = null_ptr;
  264. X        m.no_con3[mod] = null_ptr;
  265. X        m.no_con4[mod] = null_ptr;
  266. X    }
  267. X    return(&m);
  268. X}
  269. X
  270. X/*
  271. X * Update the modem database.  Other routines actually do the changes
  272. X * or deletions in memory.  A non-zero return code means non-fatal error.
  273. X */
  274. X
  275. Xint
  276. Xup_modem()
  277. X{
  278. X    FILE *fp, *my_fopen();
  279. X    char buf[80];
  280. X    int i;
  281. X    void error_win();
  282. X
  283. X                    /* open for write */
  284. X    if (!(fp = my_fopen(modem->m_path, "w"))) {
  285. X        sprintf(buf, "\"%s\"", modem->m_path);
  286. X        error_win(0, "No write permission on modem/TTY database file", buf);
  287. X        return(1);
  288. X    }
  289. X                    /* put back the TTY entries */
  290. X    for (i=0; i<modem->t_entries; i++)
  291. X        fprintf(fp, "TTY_%d=%s;%s;%d\n", i+1, modem->tty[i],
  292. X         modem->tname[i], modem->init_sp[i]);
  293. X
  294. X                    /* put back the modem entries */
  295. X    for (i=0; i<modem->m_entries; i++) {
  296. X        fprintf(fp, "MODEM_%da=%s;%s;%s;%s;%s\n", i+1, modem->mname[i],
  297. X         modem->init[i], modem->dial[i], modem->suffix[i],
  298. X         modem->hang_up[i]);
  299. X
  300. X        fprintf(fp, "MODEM_%db=%c;%s;%s;%s;%s;%s;%s\n", i+1,
  301. X         modem->auto_baud[i], modem->con_3[i], modem->con_12[i],
  302. X         modem->con_24[i], modem->con_48[i], modem->con_96[i],
  303. X         modem->con_192[i]);
  304. X
  305. X        fprintf(fp, "MODEM_%dc=%s;%s;%s;%s\n", i+1, modem->no_con1[i],
  306. X         modem->no_con2[i], modem->no_con3[i], modem->no_con4[i]);
  307. X    }
  308. X
  309. X    fclose(fp);
  310. X    return(0);
  311. X}
  312. X
  313. X/*
  314. X * See if the new modem is already in the database.  If it's not, create
  315. X * a slot for it and update the modem->m_cur variable.
  316. X */
  317. X
  318. Xvoid
  319. Xcreate_modem(str)
  320. Xchar *str;
  321. X{
  322. X    int i;
  323. X    char *str_rep(), buf[80];
  324. X    void error_win();
  325. X                    /* modem entry already exists? */
  326. X    for (i=0; i<modem->m_entries; i++) {
  327. X        if (!strcmp(str, modem->mname[i]))
  328. X            return;
  329. X    }
  330. X                    /* empty slot available? */
  331. X    if (modem->m_entries == NUM_MODEM) {
  332. X        sprintf(buf, "\"%s\"", modem->m_path);
  333. X        error_win(0, "No empty modem slots in", buf);
  334. X        return;
  335. X    }
  336. X                    /* create a new entry */
  337. X    i = modem->m_entries;
  338. X    modem->mname[i] = str_rep(modem->mname[i], str);
  339. X
  340. X                    /* update number of entries */
  341. X    modem->m_entries++;
  342. X    return;
  343. X}
  344. X
  345. X/*
  346. X * See if the modem names in the list still need to be in the database.
  347. X * If you find a "lost" entry, delete it and collapse the list.
  348. X */
  349. X
  350. Xvoid
  351. Xdel_modem()
  352. X{
  353. X    extern char *null_ptr;
  354. X    int i, j, match;
  355. X    char *str_rep();
  356. X    void free_ptr();
  357. X
  358. X    for (i=0; i<modem->m_entries; i++) {
  359. X        match = 0;
  360. X        for (j=0; j<modem->t_entries; j++) {
  361. X            if (!strcmp(modem->mname[i], modem->tname[j])) {
  362. X                match++;
  363. X                break;
  364. X            }
  365. X        }
  366. X                    /* found a "lost" modem name */
  367. X        if (!match) {
  368. X            for (j=i; j<modem->m_entries-1; j++) {
  369. X                    /* copy the info */
  370. X                modem->mname[j] = str_rep(modem->mname[j], modem->mname[j+1]);
  371. X                modem->init[j] = str_rep(modem->init[j], modem->init[j+1]);
  372. X                modem->dial[j] = str_rep(modem->dial[j], modem->dial[j+1]);
  373. X                modem->suffix[j] = str_rep(modem->suffix[j], modem->suffix[j+1]);
  374. X                modem->hang_up[j] = str_rep(modem->hang_up[j], modem->hang_up[j+1]);
  375. X
  376. X                modem->auto_baud[j] = modem->auto_baud[j+1];
  377. X                modem->con_3[j] = str_rep(modem->con_3[j], modem->con_3[j+1]);
  378. X                modem->con_12[j] = str_rep(modem->con_12[j], modem->con_12[j+1]);
  379. X                modem->con_24[j] = str_rep(modem->con_24[j], modem->con_24[j+1]);
  380. X                modem->con_48[j] = str_rep(modem->con_48[j], modem->con_48[j+1]);
  381. X                modem->con_96[j] = str_rep(modem->con_96[j], modem->con_96[j+1]);
  382. X                modem->con_192[j] = str_rep(modem->con_192[j], modem->con_192[j+1]);
  383. X
  384. X                modem->no_con1[j] = str_rep(modem->no_con1[j], modem->no_con1[j+1]);
  385. X                modem->no_con2[j] = str_rep(modem->no_con2[j], modem->no_con2[j+1]);
  386. X                modem->no_con3[j] = str_rep(modem->no_con3[j], modem->no_con3[j+1]);
  387. X                modem->no_con4[j] = str_rep(modem->no_con4[j], modem->no_con4[j+1]);
  388. X            }
  389. X            j = modem->m_entries -1;
  390. X
  391. X            free_ptr(modem->mname[j]);
  392. X            free_ptr(modem->init[j]);
  393. X            free_ptr(modem->dial[j]);
  394. X            free_ptr(modem->suffix[j]);
  395. X            free_ptr(modem->hang_up[j]);
  396. X
  397. X            free_ptr(modem->con_3[j]);
  398. X            free_ptr(modem->con_12[j]);
  399. X            free_ptr(modem->con_24[j]);
  400. X            free_ptr(modem->con_48[j]);
  401. X            free_ptr(modem->con_96[j]);
  402. X            free_ptr(modem->con_192[j]);
  403. X
  404. X            free_ptr(modem->no_con1[j]);
  405. X            free_ptr(modem->no_con2[j]);
  406. X            free_ptr(modem->no_con3[j]);
  407. X            free_ptr(modem->no_con4[j]);
  408. X
  409. X                    /* create an empty entry */
  410. X            modem->mname[j] = null_ptr;
  411. X            modem->init[j] = null_ptr;
  412. X            modem->dial[j] = null_ptr;
  413. X            modem->suffix[j] = null_ptr;
  414. X            modem->hang_up[j] = null_ptr;
  415. X
  416. X            modem->auto_baud[j] = 'Y';
  417. X            modem->con_3[j] = null_ptr;
  418. X            modem->con_12[j] = null_ptr;
  419. X            modem->con_24[j] = null_ptr;
  420. X            modem->con_48[j] = null_ptr;
  421. X            modem->con_96[j] = null_ptr;
  422. X            modem->con_192[j] = null_ptr;
  423. X
  424. X            modem->no_con1[j] = null_ptr;
  425. X            modem->no_con2[j] = null_ptr;
  426. X            modem->no_con3[j] = null_ptr;
  427. X            modem->no_con4[j] = null_ptr;
  428. X
  429. X                    /* update the counts */
  430. X            modem->m_entries--;
  431. X            if (modem->m_cur >= modem->m_entries)
  432. X                modem->m_cur = -1;
  433. X            return;
  434. X        }
  435. X    }
  436. X    return;
  437. X}
  438. SHAR_EOF
  439. if test 9951 -ne "`wc -c < 'm_lib.c'`"
  440. then
  441.     echo shar: "error transmitting 'm_lib.c'" '(should have been 9951 characters)'
  442. fi
  443. fi
  444. echo shar: "extracting 'macro.c'" '(5246 characters)'
  445. if test -f 'macro.c'
  446. then
  447.     echo shar: "will not over-write existing file 'macro.c'"
  448. else
  449. sed 's/^X//' << \SHAR_EOF > 'macro.c'
  450. X/*
  451. X * The keyboard macro feature.  Displays (and prompts for editing) the
  452. X * macros assigned to the shifted number keys.  Prompts for saving
  453. X * changes to disk.
  454. X */
  455. X
  456. X#include <stdio.h>
  457. X#include <curses.h>
  458. X#include "config.h"
  459. X#include "misc.h"
  460. X#include "param.h"
  461. X
  462. Xvoid
  463. Xmacro()
  464. X{
  465. X    extern int fd;
  466. X    WINDOW *ma_win, *newwin();
  467. X    int ans, changed;
  468. X    char *mac, *str_rep(), *mac_prompt();
  469. X
  470. X    ma_win = newwin(18, 65, 2, 15);
  471. X    mvwattrstr(ma_win, 1, 25, A_BOLD, "Keyboard Macros");
  472. X    horizontal(ma_win, 2, 0, 65);
  473. X    mvwprintw(ma_win, 4, 0, " %4.4s-!  %-50.50s\n", param->ascii_hot, param->mac_1);
  474. X    wprintw(ma_win, " %4.4s-@  %-50.50s\n", param->ascii_hot, param->mac_2);
  475. X    wprintw(ma_win, " %4.4s-#  %-50.50s\n", param->ascii_hot, param->mac_3);
  476. X    wprintw(ma_win, " %4.4s-$  %-50.50s\n", param->ascii_hot, param->mac_4);
  477. X    wprintw(ma_win, " %4.4s-%%  %-50.50s\n", param->ascii_hot, param->mac_5);
  478. X    wprintw(ma_win, " %4.4s-^  %-50.50s\n", param->ascii_hot, param->mac_6);
  479. X    wprintw(ma_win, " %4.4s-&  %-50.50s\n", param->ascii_hot, param->mac_7);
  480. X    wprintw(ma_win, " %4.4s-*  %-50.50s\n", param->ascii_hot, param->mac_8);
  481. X    wprintw(ma_win, " %4.4s-(  %-50.50s\n", param->ascii_hot, param->mac_9);
  482. X    wprintw(ma_win, " %4.4s-)  %-50.50s\n", param->ascii_hot, param->mac_0);
  483. X    mvwaddstr(ma_win, 15, 5, "Macro key to revise:");
  484. X    box(ma_win, VERT, HORZ);
  485. X                    /* on the bottom line */
  486. X    mvwaddstr(ma_win, 17, 21, " Press <ESC> to continue ");
  487. X    wmove(ma_win, 15, 26);
  488. X    wrefresh(ma_win);
  489. X
  490. X    changed = 0;
  491. X
  492. X    while ((ans = wgetch(ma_win)) != ESC) {
  493. X        switch (ans) {
  494. X            case '!':    /* shifted 1 */
  495. X                if ((mac = mac_prompt(ans, param->mac_1)) != NULL) {
  496. X                    param->mac_1 = str_rep(param->mac_1, mac);
  497. X                    clear_line(ma_win, 4, 9, TRUE);
  498. X                    mvwattrstr(ma_win, 4, 9, A_BOLD, mac);
  499. X                    changed++;
  500. X                }
  501. X                break;
  502. X            case '@':    /* shifted 2 */
  503. X                if ((mac = mac_prompt(ans, param->mac_2)) != NULL) {
  504. X                    param->mac_2 = str_rep(param->mac_2, mac);
  505. X                    clear_line(ma_win, 5, 9, TRUE);
  506. X                    mvwattrstr(ma_win, 5, 9, A_BOLD, mac);
  507. X                    changed++;
  508. X                }
  509. X                break;
  510. X            case '#':    /* shifted 3 */
  511. X                if ((mac = mac_prompt(ans, param->mac_3)) != NULL) {
  512. X                    param->mac_3 = str_rep(param->mac_3, mac);
  513. X                    clear_line(ma_win, 6, 9, TRUE);
  514. X                    mvwattrstr(ma_win, 6, 9, A_BOLD, mac);
  515. X                    changed++;
  516. X                }
  517. X                break;
  518. X            case '$':    /* shifted 4 */
  519. X                if ((mac = mac_prompt(ans, param->mac_4)) != NULL) {
  520. X                    param->mac_4 = str_rep(param->mac_4, mac);
  521. X                    clear_line(ma_win, 7, 9, TRUE);
  522. X                    mvwattrstr(ma_win, 7, 9, A_BOLD, mac);
  523. X                    changed++;
  524. X                }
  525. X                break;
  526. X            case '%':    /* shifted 5 */
  527. X                if ((mac = mac_prompt(ans, param->mac_5)) != NULL) {
  528. X                    param->mac_5 = str_rep(param->mac_5, mac);
  529. X                    clear_line(ma_win, 8, 9, TRUE);
  530. X                    mvwattrstr(ma_win, 8, 9, A_BOLD, mac);
  531. X                    changed++;
  532. X                }
  533. X                break;
  534. X            case '^':    /* shifted 6 */
  535. X                if ((mac = mac_prompt(ans, param->mac_6)) != NULL) {
  536. X                    param->mac_6 = str_rep(param->mac_6, mac);
  537. X                    clear_line(ma_win, 9, 9, TRUE);
  538. X                    mvwattrstr(ma_win, 9, 9, A_BOLD, mac);
  539. X                    changed++;
  540. X                }
  541. X                break;
  542. X            case '&':    /* shifted 7 */
  543. X                if ((mac = mac_prompt(ans, param->mac_7)) != NULL) {
  544. X                    param->mac_7 = str_rep(param->mac_7, mac);
  545. X                    clear_line(ma_win, 10, 9, TRUE);
  546. X                    mvwattrstr(ma_win, 10, 9, A_BOLD, mac);
  547. X                    changed++;
  548. X                }
  549. X                break;
  550. X            case '*':    /* shifted 8 */
  551. X                if ((mac = mac_prompt(ans, param->mac_8)) != NULL) {
  552. X                    param->mac_8 = str_rep(param->mac_8, mac);
  553. X                    clear_line(ma_win, 11, 9, TRUE);
  554. X                    mvwattrstr(ma_win, 11, 9, A_BOLD, mac);
  555. X                    changed++;
  556. X                }
  557. X                break;
  558. X            case '(':    /* shifted 9 */
  559. X                if ((mac = mac_prompt(ans, param->mac_9)) != NULL) {
  560. X                    param->mac_9 = str_rep(param->mac_9, mac);
  561. X                    clear_line(ma_win, 12, 9, TRUE);
  562. X                    mvwattrstr(ma_win, 12, 9, A_BOLD, mac);
  563. X                    changed++;
  564. X                }
  565. X                break;
  566. X            case ')':    /* shifted 0 */
  567. X                if ((mac = mac_prompt(ans, param->mac_0)) != NULL) {
  568. X                    param->mac_0 = str_rep(param->mac_0, mac);
  569. X                    clear_line(ma_win, 13, 9, TRUE);
  570. X                    mvwattrstr(ma_win, 13, 9, A_BOLD, mac);
  571. X                    changed++;
  572. X                }
  573. X                break;
  574. X            default:
  575. X                beep();
  576. X                break;
  577. X        }
  578. X        touchwin(ma_win);
  579. X        wmove(ma_win, 15, 26);
  580. X        wrefresh(ma_win);
  581. X    }
  582. X                    /* if something changed */
  583. X    if (changed) {
  584. X                    /* save to disk? */
  585. X        if (yes_prompt(ma_win, 15, 30, A_BOLD, "Save to disk")) {
  586. X            if (up_param()) {
  587. X                touchwin(ma_win);
  588. X                wrefresh(ma_win);
  589. X            }
  590. X        }
  591. X    }
  592. X    if (fd == -1) {
  593. X        werase(ma_win);
  594. X        wrefresh(ma_win);
  595. X    }
  596. X    delwin(ma_win);
  597. X    return;
  598. X}
  599. X
  600. X/*
  601. X * Sounds like McDonalds doesn't it?  Actually, it opens a new window
  602. X * and prompts for the new macro.  Returns a pointer to the new string.
  603. X * Since it uses get_str(), the return value points to a static area.
  604. X */
  605. X
  606. Xstatic char *
  607. Xmac_prompt(key, string)
  608. Xchar key, *string;
  609. X{
  610. X    extern char *null_ptr;
  611. X    WINDOW *mp_win, *newwin();
  612. X    char *new, *get_str();
  613. X
  614. X    mp_win = newwin(6, 65, 8, 0);
  615. X    mvwprintw(mp_win, 2, 3, "%4.4s-%c  %-50.50s", param->ascii_hot, key, string);
  616. X    mvwaddstr(mp_win, 3, 5, "New : ");
  617. X    box(mp_win, VERT, HORZ);
  618. X    wrefresh(mp_win);
  619. X
  620. X    if ((new = get_str(mp_win, 50, "", "\n")) != NULL) {
  621. X                    /* if CR, return NULL */
  622. X        if (*new == '\0')
  623. X            new = NULL;
  624. X                    /* if space, change to null_ptr */
  625. X        if (!strcmp(new, " "))
  626. X            new = null_ptr;
  627. X    }
  628. X
  629. X    werase(mp_win);
  630. X    wrefresh(mp_win);
  631. X    delwin(mp_win);
  632. X    return(new);
  633. X}
  634. SHAR_EOF
  635. if test 5246 -ne "`wc -c < 'macro.c'`"
  636. then
  637.     echo shar: "error transmitting 'macro.c'" '(should have been 5246 characters)'
  638. fi
  639. fi
  640. echo shar: "extracting 'main.c'" '(7580 characters)'
  641. if test -f 'main.c'
  642. then
  643.     echo shar: "will not over-write existing file 'main.c'"
  644. else
  645. sed 's/^X//' << \SHAR_EOF > 'main.c'
  646. X/*
  647. X * Pcomm is a public domain telecommunication program for Unix that
  648. X * is designed to operate similar to the MSDOS program, ProComm.
  649. X * ProComm (TM) is copyrighted by Datastorm Technologies, Inc.
  650. X *
  651. X * Emmet P. Gray            US Army, HQ III Corps & Fort Hood
  652. X * ...!uunet!uiucuxc!fthood!egray    Attn: AFZF-DE-ENV
  653. X *                    Directorate of Engineering & Housing
  654. X *                    Environmental Management Office
  655. X *                    Fort Hood, TX 76544-5057
  656. X *
  657. X *    Release v1.0    12 Mar 88
  658. X *    Release v1.1    21 Aug 88
  659. X *    Release v1.2.0     4 Feb 89
  660. X */
  661. X
  662. X#include <stdio.h>
  663. X#include <ctype.h>
  664. X#include <signal.h>
  665. X#include <curses.h>
  666. X#include <sys/types.h>
  667. X#include <sys/stat.h>
  668. X#define    MAIN
  669. X#include "config.h"
  670. X#include "dial_dir.h"
  671. X#include "extrnl.h"
  672. X#include "misc.h"
  673. X#include "modem.h"
  674. X#include "param.h"
  675. X#include "status.h"
  676. X
  677. X#ifndef OLDCURSES
  678. X#include <term.h>
  679. X#else /* OLDCURSES */
  680. X#ifdef UNIXPC
  681. X#include <sgtty.h>
  682. X#endif /* UNIXPC */
  683. Xchar tcbuf[1024];
  684. Xstruct sgttyb t_mode, c_mode;
  685. X#define cbreak crmode
  686. X#endif /* OLDCURSES */
  687. X
  688. X#ifdef SHAREDMEM
  689. Xint shm_id;
  690. X#endif /* SHAREDMEM */
  691. X
  692. Xstruct DIAL_DIR *dir;
  693. Xstruct EXTRNL *extrnl;
  694. Xstruct MODEM *modem;
  695. Xstruct PARAM *param;
  696. Xstruct STATUS *status;
  697. X
  698. Xint fd = -1;                /* file descriptor for port */
  699. Xint xmc;                /* magic cookie terminal */
  700. Xint msg_status;                /* read/write permissions on TTY */
  701. Xchar *null_ptr = "";            /* generic null pointer */
  702. X
  703. Xmain(argc, argv)
  704. Xint argc;
  705. Xchar *argv[];
  706. X{
  707. X    extern char *optarg;
  708. X    int c, i, code, quit();
  709. X    char *mytty, *ttyname(), *term, *getenv(), *sys_name, *str_dup();
  710. X    char *extra_dir, buf[80], message[80];
  711. X    struct DIAL_DIR *read_dir();
  712. X    struct EXTRNL *read_extrnl();
  713. X    struct MODEM *read_modem();
  714. X    struct PARAM *read_param();
  715. X    struct STATUS *init();
  716. X    struct stat stbuf;
  717. X    void exit(), error_win(), free_ptr();
  718. X#ifdef OLDCURSES
  719. X    char *tgetstr(), *t, tb[1024];
  720. X    t = tcbuf;
  721. X#endif /* OLDCURSES */
  722. X
  723. X    signal(SIGINT, SIG_IGN);
  724. X    signal(SIGQUIT, SIG_IGN);
  725. X    signal(SIGTERM, quit);
  726. X    signal(SIGHUP, quit);
  727. X
  728. X    sys_name = NULL;
  729. X    extra_dir = NULL;
  730. X                    /* the command line */
  731. X    while ((c = getopt(argc, argv, "d:f:")) != EOF) {
  732. X        switch (c) {
  733. X            case 'd':    /* the extra directory to search */
  734. X                extra_dir = str_dup(optarg);
  735. X                break;
  736. X            case 'f':    /* the short cut into the dialing dir */
  737. X                sys_name = str_dup(optarg);
  738. X                break;
  739. X            case '?':    /* default */
  740. X                fprintf(stderr, "Usage: pcomm [-d directory] [-f system name]\n");
  741. X                exit(1);
  742. X                break;
  743. X        }
  744. X    }
  745. X                    /* get terminal type */
  746. X    term = getenv("TERM");
  747. X    if (term == NULL || *term == '\0') {
  748. X        fprintf(stderr, "Windows not supported (TERM not defined)\n");
  749. X        exit(1);
  750. X    }
  751. X                    /* see if terminfo entry exists */
  752. X#ifdef OLDCURSES
  753. X    i = tgetent(tb, term);
  754. X#else /* OLDCURSES */
  755. X    setupterm(term, 1, &i);
  756. X#endif /* OLDCURSES */
  757. X
  758. X    if (i != 1) {
  759. X        fprintf(stderr, "Windows not supported (no terminfo data for \"%s\")\n", term);
  760. X        exit(1);
  761. X    }
  762. X                    /* minimum screen size */
  763. X#ifdef OLDCURSES
  764. X    if (tgetnum("co") < 80 || tgetnum("li") < 24) {
  765. X#else /* OLDCURSES */
  766. X    if (columns < 80 || lines < 24) {
  767. X#endif /* OLDCURSES */
  768. X        fprintf(stderr, "Windows not supported (minimum 80x24 screen required)\n");
  769. X        exit(1);
  770. X    }
  771. X                    /* must have cursor movement */
  772. X#ifdef OLDCURSES
  773. X    if (tgetstr("cm", &t) == NULL) {
  774. X#else /* OLDCURSES */
  775. X    if (cursor_address == NULL) {
  776. X#endif /* OLDCURSES */
  777. X        fprintf(stderr, "Windows not supported (terminal too dumb)\n");
  778. X        exit(1);
  779. X    }
  780. X                    /* load magic cookie variable */
  781. X#ifdef OLDCURSES
  782. X    xmc = tgetnum("sg");
  783. X#else /* OLDCURSES */
  784. X    xmc = magic_cookie_glitch;
  785. X#endif /* OLDCURSES */
  786. X                    /* ok... now let's go! */
  787. X#ifdef OLDCURSES
  788. X    ioctl(0, TIOCGETP, &t_mode);
  789. X#endif /* OLDCURSES */
  790. X
  791. X    initscr();
  792. X    nonl();
  793. X    cbreak();
  794. X    noecho();
  795. X
  796. X#ifdef OLDCURSES
  797. X    ioctl(0, TIOCGETP, &c_mode);
  798. X#endif /* OLDCURSES */
  799. X
  800. X    dir = (struct DIAL_DIR *) NULL;
  801. X    extrnl = (struct EXTRNL *) NULL;
  802. X    param = (struct PARAM *) NULL;
  803. X    modem = (struct MODEM *) NULL;
  804. X                    /* show the herald, return status */
  805. X    status = init(sys_name);
  806. X                    /* get "msgs" status */
  807. X    mytty = ttyname(0);
  808. X    stat(mytty, &stbuf);
  809. X    msg_status = stbuf.st_mode & 0777;
  810. X    chmod(mytty, 0600);
  811. X
  812. X    mvaddstr(12, 31, "Initializing...");
  813. X    refresh();
  814. X                    /* read the support files */
  815. X    param = read_param(extra_dir);
  816. X    dir = read_dir(extra_dir);
  817. X    extrnl = read_extrnl(extra_dir);
  818. X    modem = read_modem(extra_dir);
  819. X
  820. X                    /* warning about screen size */
  821. X    if (LINES > MAX_ROW || COLS > MAX_COL-1)
  822. X        error_win(0, "Your screen size exceeds an internal Pcomm limit",
  823. X         "The edges of the screen may contain garbage");
  824. X
  825. X                    /* short-cut to dialing window? */
  826. X    code = 0;
  827. X    if (sys_name != NULL) {
  828. X        for (i=1; i<dir->d_entries+1; i++) {
  829. X            if (match_ci(dir->name[i], sys_name)) {
  830. X                dir->q_num[0] = i;
  831. X                dir->d_cur = i;
  832. X                break;
  833. X            }
  834. X        }
  835. X                    /* if match is found */
  836. X        if (dir->q_num[0] != -1)
  837. X            code = dial_win();
  838. X        else {
  839. X            sprintf(buf, "Can't match \"%s\" in dialing directory", sys_name);
  840. X            sprintf(message, "file \"%s\"", dir->d_path);
  841. X            error_win(0, buf, message);
  842. X        }
  843. X        free_ptr(sys_name);
  844. X    }
  845. X                    /* start terminal dialogue */
  846. X    terminal(extra_dir, code);
  847. X    exit(0);
  848. X}
  849. X
  850. X/*
  851. X * Something dreadful happened...  Clean up the mess we made with the
  852. X * TTY driver and release the phone line.
  853. X */
  854. X
  855. Xint
  856. Xquit()
  857. X{
  858. X    void cleanup();
  859. X
  860. X    cleanup(1);
  861. X                    /* never returns... */
  862. X    return(0);
  863. X}
  864. X
  865. X/*
  866. X * Check write permission with the real UID and GID.  Returns a 0 on
  867. X * permission denied, 1 on OK, and 2 on OK-but the file already exists.
  868. X */
  869. X
  870. Xint
  871. Xcan_write(file)
  872. Xchar *file;
  873. X{
  874. X    char *p, path[256], *strcpy(), *strrchr();
  875. X
  876. X    strcpy(path, file);
  877. X                    /* dissect the path component */
  878. X    if (p = strrchr(path, '/'))
  879. X        *p = '\0';
  880. X    else
  881. X        strcpy(path, ".");
  882. X                    /* if it already exists */
  883. X    if (!access(file, 0)) {
  884. X        if (!access(file, 2))
  885. X            return(OK_BUT_EXISTS);
  886. X        return(DENIED);
  887. X    }
  888. X                    /* if path is writable */
  889. X    if (!access(path, 2))
  890. X        return(WRITE_OK);
  891. X    return(DENIED);
  892. X}
  893. X
  894. X/*
  895. X * Check the read and write permissions before opening a file.  This
  896. X * is a horrible kludge to work around the fact that a lot of systems
  897. X * that claim to be SVID compatible don't treat setuid(2) and setgid(2)
  898. X * properly.  For example, on a Masscomp, you can't flip-flop back and
  899. X * forth between the real and effective UID/GID.
  900. X */
  901. X
  902. XFILE *
  903. Xmy_fopen(file, mode)
  904. Xchar *file, *mode;
  905. X{
  906. X    FILE *fp;
  907. X
  908. X#ifdef SETUGID
  909. X#ifdef SETUID_BROKE
  910. X    switch (*mode) {
  911. X        case 'a':
  912. X        case 'w':
  913. X            switch(can_write(file)) {
  914. X                case DENIED:
  915. X                    fp = (FILE *) NULL;
  916. X                    break;
  917. X                case OK_BUT_EXISTS:
  918. X                    fp = fopen(file, mode);
  919. X                    break;
  920. X                case WRITE_OK:
  921. X                    fp = fopen(file, mode);
  922. X                    chown(file, getuid(), getgid());
  923. X                    break;
  924. X            }
  925. X            break;
  926. X        case 'r':
  927. X            if (access(file, 4))
  928. X                fp = (FILE *) NULL;
  929. X            else
  930. X                fp = fopen(file, mode);
  931. X            break;
  932. X    }
  933. X#else /* SETUID_BROKE */
  934. X    int euid, egid;
  935. X
  936. X    euid = geteuid();
  937. X    egid = getegid();
  938. X                    /* abdicate the throne */
  939. X    setuid(getuid());
  940. X    setgid(getgid());
  941. X
  942. X    fp = fopen(file, mode);
  943. X                    /* put things back */
  944. X    setuid(euid);
  945. X    setgid(egid);
  946. X#endif /* SETUID_BROKE */
  947. X    return(fp);
  948. X#else /* SETUGID */
  949. X    return(fopen(file, mode));
  950. X#endif /* SETUGID */
  951. X}
  952. X
  953. X/*
  954. X * See if s2 in contained in s1 (case insensitive).  Returns a 1 on yes,
  955. X * and a 0 on no.
  956. X */
  957. X
  958. Xmatch_ci(s1, s2)
  959. Xchar *s1, *s2;
  960. X{
  961. X    int i;
  962. X    char str1[128], str2[128], *strstr();
  963. X
  964. X                    /* copy the strings to lower case */
  965. X    i = 0;
  966. X    while(*s1) {
  967. X        if (isupper(*s1))
  968. X            str1[i++] = tolower(*s1);
  969. X        else
  970. X            str1[i++] = *s1;
  971. X
  972. X        if (i >= 127)
  973. X            break;
  974. X        s1++;
  975. X    }
  976. X    str1[i] = '\0';
  977. X
  978. X    i = 0;
  979. X    while(*s2) {
  980. X        if (isupper(*s2))
  981. X            str2[i++] = tolower(*s2);
  982. X        else
  983. X            str2[i++] = *s2;
  984. X
  985. X        if (i >= 127)
  986. X            break;
  987. X        s2++;
  988. X    }
  989. X    str2[i] = '\0';
  990. X                    /* do they match? */
  991. X    if (strstr(str1, str2))
  992. X        return(1);
  993. X    return(0);
  994. X}
  995. SHAR_EOF
  996. if test 7580 -ne "`wc -c < 'main.c'`"
  997. then
  998.     echo shar: "error transmitting 'main.c'" '(should have been 7580 characters)'
  999. fi
  1000. fi
  1001. echo shar: "extracting 'matches.c'" '(754 characters)'
  1002. if test -f 'matches.c'
  1003. then
  1004.     echo shar: "will not over-write existing file 'matches.c'"
  1005. else
  1006. sed 's/^X//' << \SHAR_EOF > 'matches.c'
  1007. X/*
  1008. X * See if two strings match.  Returns a 0 on success, and a 1 on failure.
  1009. X * This is an external program to be used in shell scripts.
  1010. X */
  1011. X
  1012. X#define STRSTR
  1013. X
  1014. X#include <stdio.h>
  1015. X
  1016. Xmain(argc, argv)
  1017. Xint argc;
  1018. Xchar *argv[];
  1019. X{
  1020. X    char *strstr();
  1021. X    void exit();
  1022. X
  1023. X    if (argc != 3) {
  1024. X        fprintf(stderr, "Usage: matches string1 string2\n");
  1025. X        exit(-1);
  1026. X    }
  1027. X
  1028. X    if (strstr(argv[1], argv[2]))
  1029. X        exit(0);
  1030. X    exit(1);
  1031. X}
  1032. X
  1033. X#ifdef STRSTR
  1034. X/*
  1035. X * Return a pointer to the first occurance of string str2 in str1.
  1036. X * Returns a NULL if str2 is not in str1.
  1037. X */
  1038. X
  1039. Xchar *
  1040. Xstrstr(str1, str2)
  1041. Xchar *str1, *str2;
  1042. X{
  1043. X    int len;
  1044. X
  1045. X    len = strlen(str2);
  1046. X    while (*str1) {
  1047. X        if (*str2 == *str1) {
  1048. X            if (!strncmp(str2, str1, len))
  1049. X                return(str1);
  1050. X        }
  1051. X        str1++;
  1052. X    }
  1053. X    return(NULL);
  1054. X}
  1055. X#endif /* STRSTR */
  1056. SHAR_EOF
  1057. if test 754 -ne "`wc -c < 'matches.c'`"
  1058. then
  1059.     echo shar: "error transmitting 'matches.c'" '(should have been 754 characters)'
  1060. fi
  1061. fi
  1062. echo shar: "extracting 'misc.h'" '(1549 characters)'
  1063. if test -f 'misc.h'
  1064. then
  1065.     echo shar: "will not over-write existing file 'misc.h'"
  1066. else
  1067. sed 's/^X//' << \SHAR_EOF > 'misc.h'
  1068. X/*
  1069. X * Definitions to support the home-grown curses(3) functions and to make
  1070. X * the old curses(3) routines happy.  ("config.h" must be included first).
  1071. X */
  1072. X
  1073. X#define mvwattrstr(w,y,x,a,s)    (wmove(w,y,x)==ERR?ERR:wattrstr(w,a,s))
  1074. X#define mvwattrch(w,y,x,a,c)    (wmove(w,y,x)==ERR?ERR:wattrch(w,a,c))
  1075. X#define mvwattrnum(w,y,x,a,n)    (wmove(w,y,x)==ERR?ERR:wattrnum(w,a,n))
  1076. X#define mvattrstr(y,x,a,s)    (wmove(stdscr,y,x)==ERR?ERR:wattrstr(stdscr,a,s))
  1077. X#define mvattrch(y,x,a,c)    (wmove(stdscr,y,x)==ERR?ERR:wattrch(stdscr,a,c))
  1078. X#define mvattrnum(y,x,a,n)    (wmove(stdscr,y,x)==ERR?ERR:wattrnum(stdscr,a,n))
  1079. X#define attrstr(a,s)        wattrstr(stdscr,a,s)
  1080. X#define attrch(a,c)        wattrch(stdscr,a,c)
  1081. X#define attrnum(a,n)        wattrnum(stdscr,a,n)
  1082. X
  1083. X#ifdef OLDCURSES
  1084. X#ifdef NOPROMOTE
  1085. X#define A_BOLD        0
  1086. X#define A_BLINK        0
  1087. X#define A_REVERSE    1
  1088. X#define A_DIM        0
  1089. X#define A_STANDOUT    1
  1090. X#define A_UNDERLINE    0
  1091. X#else /* NOPROMOTE */
  1092. X#define A_BOLD        1
  1093. X#define A_BLINK        1
  1094. X#define A_REVERSE    1
  1095. X#define A_DIM        1
  1096. X#define A_STANDOUT    1
  1097. X#define A_UNDERLINE    1
  1098. X#endif /* NOPROMOTE */
  1099. X#endif /* OLDCURSES */
  1100. X
  1101. X#ifdef OLDCURSES
  1102. Xtypedef char chtype;
  1103. X#endif /* OLDCURSES */
  1104. X
  1105. X#ifdef ACS_HLINE
  1106. X#define VERT        (chtype)0
  1107. X#define HORZ        (chtype)0
  1108. X#else /* ACS_HLINE */
  1109. X#define VERT        (chtype)'|'
  1110. X#define HORZ        (chtype)'-'
  1111. X#define ACS_VLINE    (chtype)'|'
  1112. X#define ACS_HLINE    (chtype)'-'
  1113. X#endif /* ACS_HLINE */
  1114. X
  1115. X/*
  1116. X * Other miscellaneous stuff
  1117. X */
  1118. X
  1119. X#define BEL        7
  1120. X#define BS        8
  1121. X#define ESC        27
  1122. X#define DEL        127
  1123. X
  1124. X#define MANUAL_CLEAR    0
  1125. X#define AUTO_CLEAR    1
  1126. X
  1127. X#define DENIED        0
  1128. X#define WRITE_OK    1
  1129. X#define OK_BUT_EXISTS    2
  1130. SHAR_EOF
  1131. if test 1549 -ne "`wc -c < 'misc.h'`"
  1132. then
  1133.     echo shar: "error transmitting 'misc.h'" '(should have been 1549 characters)'
  1134. fi
  1135. fi
  1136. echo shar: "extracting 'modem.h'" '(1538 characters)'
  1137. if test -f 'modem.h'
  1138. then
  1139.     echo shar: "will not over-write existing file 'modem.h'"
  1140. else
  1141. sed 's/^X//' << \SHAR_EOF > 'modem.h'
  1142. X/*
  1143. X * The modem and TTY databases.  The first 3 elements make up the TTY
  1144. X * database, the next 16 make up the modem database.  A "tname" in common
  1145. X * with a "mname" link the two together.
  1146. X */
  1147. X
  1148. X#define NUM_TTY        10
  1149. X#define NUM_MODEM    10
  1150. X
  1151. Xstruct MODEM {
  1152. X    char    *tty[NUM_TTY];        /* TTY names */
  1153. X    char    *tname[NUM_TTY];    /* modem name */
  1154. X    int    init_sp[NUM_TTY];    /* initialization baud rate */
  1155. X
  1156. X    char    *mname[NUM_MODEM];    /* modem name (matches tname above) */
  1157. X    char    *init[NUM_MODEM];    /* initialization */
  1158. X    char    *dial[NUM_MODEM];    /* dial command */
  1159. X    char    *suffix[NUM_MODEM];    /* dialing command suffix */
  1160. X    char    *hang_up[NUM_MODEM];    /* hang up the modem */
  1161. X    char    auto_baud[NUM_MODEM];    /* should we sync baud rates? */
  1162. X    char    *con_3[NUM_MODEM];    /* 300 baud connect message */
  1163. X    char    *con_12[NUM_MODEM];    /* 1200 baud connect message */
  1164. X    char    *con_24[NUM_MODEM];    /* 2400 baud connect message */
  1165. X    char    *con_48[NUM_MODEM];    /* 4800 baud connect message */
  1166. X    char    *con_96[NUM_MODEM];    /* 9600 baud connect message */
  1167. X    char    *con_192[NUM_MODEM];    /* 19200 baud connect message */
  1168. X    char    *no_con1[NUM_MODEM];    /* no connect #1 */
  1169. X    char    *no_con2[NUM_MODEM];    /* no connect #2 */
  1170. X    char    *no_con3[NUM_MODEM];    /* no connect #3 */
  1171. X    char    *no_con4[NUM_MODEM];    /* no connect #4 */
  1172. X
  1173. X    int    t_entries;        /* number of TTY entries */
  1174. X    int    m_entries;        /* number of modem entries */
  1175. X    int    t_cur;            /* current TTY entry number */
  1176. X    int    m_cur;            /* current modem entry number */
  1177. X
  1178. X    char    *m_path;        /* path to the pcomm.modem file */
  1179. X};
  1180. X
  1181. X#ifndef MAIN
  1182. Xextern struct MODEM *modem;
  1183. X#endif /* MAIN */
  1184. SHAR_EOF
  1185. if test 1538 -ne "`wc -c < 'modem.h'`"
  1186. then
  1187.     echo shar: "error transmitting 'modem.h'" '(should have been 1538 characters)'
  1188. fi
  1189. fi
  1190. echo shar: "extracting 'modem_break.c'" '(407 characters)'
  1191. if test -f 'modem_break.c'
  1192. then
  1193.     echo shar: "will not over-write existing file 'modem_break.c'"
  1194. else
  1195. sed 's/^X//' << \SHAR_EOF > 'modem_break.c'
  1196. X/*
  1197. X * Send a modem break.  This is an external program to be used in shell
  1198. X * scripts.
  1199. X */
  1200. X
  1201. X#include <stdio.h>
  1202. X#ifdef BSD
  1203. X#include <sgtty.h>
  1204. X#else /* BSD */
  1205. X#include <termio.h>
  1206. X#endif /* BSD */
  1207. X
  1208. Xmain()
  1209. X{
  1210. X    unsigned int sleep();
  1211. X
  1212. X#ifdef BSD
  1213. X    ioctl(1, TIOCSBRK, (struct sgttyb *) 0);
  1214. X    sleep(1);
  1215. X    return(ioctl(1, TIOCCBRK, (struct sgttyb *) 0));
  1216. X#else /* BSD */
  1217. X    return(ioctl(1, TCSBRK, 0));
  1218. X#endif /* BSD */
  1219. X}
  1220. SHAR_EOF
  1221. if test 407 -ne "`wc -c < 'modem_break.c'`"
  1222. then
  1223.     echo shar: "error transmitting 'modem_break.c'" '(should have been 407 characters)'
  1224. fi
  1225. fi
  1226. echo shar: "extracting 'n_shell.c'" '(1336 characters)'
  1227. if test -f 'n_shell.c'
  1228. then
  1229.     echo shar: "will not over-write existing file 'n_shell.c'"
  1230. else
  1231. sed 's/^X//' << \SHAR_EOF > 'n_shell.c'
  1232. X/*
  1233. X * Spawn a "native" shell.  Native means the shell found in the SHELL
  1234. X * environmental variable.
  1235. X */
  1236. X
  1237. X#include <stdio.h>
  1238. X#include <signal.h>
  1239. X#include <curses.h>
  1240. X#include "config.h"
  1241. X
  1242. Xvoid
  1243. Xn_shell()
  1244. X{
  1245. X    WINDOW *sh_win, *newwin();
  1246. X    SIG_TYPE (*istat)(), (*qstat)();
  1247. X    int sig_status, spid, w;
  1248. X    char *shell, *shellpath, *getenv(), *strrchr();
  1249. X    unsigned int sleep();
  1250. X    void _exit();
  1251. X                    /* a full window */
  1252. X    sh_win = newwin(LINES, COLS, 0, 0);
  1253. X
  1254. X    touchwin(sh_win);
  1255. X    waddstr(sh_win, "Pcomm <=> Unix gateway, use ^D or 'exit' to return\n");
  1256. X    wrefresh(sh_win);
  1257. X                    /* out of curses mode */
  1258. X    resetterm();
  1259. X
  1260. X    shellpath = getenv("SHELL");
  1261. X    if (shellpath == NULL || *shellpath == '\0')
  1262. X        shellpath = "/bin/sh";
  1263. X
  1264. X    if (shell = strrchr(shellpath, '/'))
  1265. X        shell++;
  1266. X    else {
  1267. X        shellpath = "/bin/sh";
  1268. X        shell = "sh";
  1269. X    }
  1270. X
  1271. X    if (!(spid = fork())) {
  1272. X        signal(SIGINT, SIG_DFL);
  1273. X        signal(SIGQUIT, SIG_DFL);
  1274. X#ifdef SETUGID
  1275. X        setgid(getgid());
  1276. X        setuid(getuid());
  1277. X#endif /* SETUGID */
  1278. X        execl(shellpath, shell, "-i", (char *) 0);
  1279. X        _exit(1);
  1280. X    }
  1281. X    istat = signal(SIGINT, SIG_IGN);
  1282. X    qstat = signal(SIGQUIT, SIG_IGN);
  1283. X
  1284. X    while ((w = wait(&sig_status)) != spid && w != -1)
  1285. X        ;
  1286. X
  1287. X    signal(SIGINT, istat);
  1288. X    signal(SIGQUIT, qstat);
  1289. X                    /* back to curses mode */
  1290. X    sleep(1);
  1291. X    fixterm();
  1292. X
  1293. X    clearok(curscr, TRUE);
  1294. X    werase(sh_win);
  1295. X    wrefresh(sh_win);
  1296. X    delwin(sh_win);
  1297. X    return;
  1298. X}
  1299. SHAR_EOF
  1300. if test 1336 -ne "`wc -c < 'n_shell.c'`"
  1301. then
  1302.     echo shar: "error transmitting 'n_shell.c'" '(should have been 1336 characters)'
  1303. fi
  1304. fi
  1305. echo shar: "extracting 'p_lib.c'" '(7337 characters)'
  1306. if test -f 'p_lib.c'
  1307. then
  1308.     echo shar: "will not over-write existing file 'p_lib.c'"
  1309. else
  1310. sed 's/^X//' << \SHAR_EOF > 'p_lib.c'
  1311. X/*
  1312. X * Routines to manipulate the pcomm.param file.
  1313. X */
  1314. X
  1315. X#include <stdio.h>
  1316. X#include "param.h"
  1317. X
  1318. X/*
  1319. X * Read the parameter structure from the pcomm.param file.  Returns a
  1320. X * pointer to a static area containing the PARAM structure.  All errors
  1321. X * are fatal.
  1322. X */
  1323. X
  1324. Xstruct PARAM *
  1325. Xread_param(extra)
  1326. Xchar *extra;
  1327. X{
  1328. X    FILE *fp, *my_fopen();
  1329. X    int i, line, oops;
  1330. X    char buf[200], *temp_token, *str, *str_dup(), *findfile();
  1331. X    char message[80], *str_tok();
  1332. X    static char *token[NUM_PARAM] = {"D_BAUD", "D_PARITY", "D_DBITS",
  1333. X    "D_SBITS", "HOT", "ASCII_HOT", "D_DUPLEX", "FLOW", "CR_IN", "CR_OUT",
  1334. X    "LOGFILE", "DUMPFILE", "STRIP", "PAUSE_CHAR", "CR_CHAR", "CTRL_CHAR",
  1335. X    "ESC_CHAR", "BRK_CHAR", "ABORT", "C_DELAY", "R_DELAY", "LECHO",
  1336. X    "EXPAND", "CR_DELAY", "PACE", "CR_UP", "LF_UP", "TIMER", "CR_DN",
  1337. X    "LF_DN", "LD_PLUS", "LD_MINUS", "LD_AT", "LD_POUND", "MAC_1",
  1338. X    "MAC_2", "MAC_3", "MAC_4", "MAC_5", "MAC_6", "MAC_7", "MAC_8",
  1339. X    "MAC_9", "MAC_0"};
  1340. X    static struct PARAM p;
  1341. X    void error_win();
  1342. X
  1343. X    if ((p.p_path = findfile(extra, "pcomm.param")) == NULL)
  1344. X        error_win(1, "Support file \"pcomm.param\" is missing", "or no read permission");
  1345. X
  1346. X    if (!(fp = my_fopen(p.p_path, "r"))) {
  1347. X        sprintf(buf, "\"%s\" for read", p.p_path);
  1348. X        error_win(1, "Can't open parameter file", buf);
  1349. X    }
  1350. X
  1351. X    oops = 0;
  1352. X    line = 0;
  1353. X    for (i=0; i<NUM_PARAM; i++) {
  1354. X        line++;
  1355. X        if (fgets(buf, 200, fp) == NULL) {
  1356. X            sprintf(message, "is truncated at line %d", line);
  1357. X            oops++;
  1358. X            break;
  1359. X        }
  1360. X                    /* parse the input line */
  1361. X        if (!(temp_token = str_tok(buf, '='))) {
  1362. X            sprintf(message, "is missing a token at line %d", line);
  1363. X            oops++;
  1364. X            break;
  1365. X        }
  1366. X        if (!(str = str_tok((char *) NULL, '\n'))) {
  1367. X            sprintf(message, "is missing a parameter at line %d", line);
  1368. X            oops++;
  1369. X            break;
  1370. X        }
  1371. X                    /* sanity checking */
  1372. X        if (strcmp(temp_token, token[i])) {
  1373. X            sprintf(message, "is corrupted at line %d", line);
  1374. X            oops++;
  1375. X            break;
  1376. X        }
  1377. X
  1378. X        switch (i) {
  1379. X                    /* used in ls_menu() */
  1380. X            case LINE_SET:
  1381. X                p.d_baud = atoi(str);
  1382. X                break;
  1383. X            case LINE_SET+1:
  1384. X                p.d_parity = *str;
  1385. X                break;
  1386. X            case LINE_SET+2:
  1387. X                p.d_dbits = atoi(str);
  1388. X                break;
  1389. X            case LINE_SET+3:
  1390. X                p.d_sbits = atoi(str);
  1391. X                break;
  1392. X
  1393. X                    /* used in term_setup() */
  1394. X            case TERM_SETUP:
  1395. X                p.hot = atoi(str);
  1396. X                break;
  1397. X            case TERM_SETUP+1:
  1398. X                p.ascii_hot = str_dup(str);
  1399. X                break;
  1400. X            case TERM_SETUP+2:
  1401. X                p.d_duplex = str_dup(str);
  1402. X                break;
  1403. X            case TERM_SETUP+3:
  1404. X                p.flow = str_dup(str);
  1405. X                break;
  1406. X            case TERM_SETUP+4:
  1407. X                p.cr_in = str_dup(str);
  1408. X                break;
  1409. X            case TERM_SETUP+5:
  1410. X                p.cr_out = str_dup(str);
  1411. X                break;
  1412. X
  1413. X                    /* used in gen_setup() */
  1414. X            case GEN_SETUP:
  1415. X                p.logfile = str_dup(str);
  1416. X                break;
  1417. X            case GEN_SETUP+1:
  1418. X                p.dumpfile = str_dup(str);
  1419. X                break;
  1420. X            case GEN_SETUP+2:
  1421. X                p.strip = str_dup(str);
  1422. X                break;
  1423. X            case GEN_SETUP+3:
  1424. X                p.pause_char = *str;
  1425. X                break;
  1426. X            case GEN_SETUP+4:
  1427. X                p.cr_char = *str;
  1428. X                break;
  1429. X            case GEN_SETUP+5:
  1430. X                p.ctrl_char = *str;
  1431. X                break;
  1432. X            case GEN_SETUP+6:
  1433. X                p.esc_char = *str;
  1434. X                break;
  1435. X            case GEN_SETUP+7:
  1436. X                p.brk_char = *str;
  1437. X                break;
  1438. X            case GEN_SETUP+8:
  1439. X                p.abort = str_dup(str);
  1440. X                break;
  1441. X
  1442. X                    /* used in gen_setup() delay_times() */
  1443. X            case DELAY_TIMES:
  1444. X                p.c_delay = atoi(str);
  1445. X                break;
  1446. X            case DELAY_TIMES+1:
  1447. X                p.r_delay = atoi(str);
  1448. X                break;
  1449. X
  1450. X                    /* used in axfer_setup() */
  1451. X            case ASCII_SETUP:
  1452. X                p.lecho = str_dup(str);
  1453. X                break;
  1454. X            case ASCII_SETUP+1:
  1455. X                p.expand = str_dup(str);
  1456. X                break;
  1457. X            case ASCII_SETUP+2:
  1458. X                p.cr_delay = atoi(str);
  1459. X                break;
  1460. X            case ASCII_SETUP+3:
  1461. X                p.pace = str_dup(str);
  1462. X                break;
  1463. X            case ASCII_SETUP+4:
  1464. X                p.cr_up = str_dup(str);
  1465. X                break;
  1466. X            case ASCII_SETUP+5:
  1467. X                p.lf_up = str_dup(str);
  1468. X                break;
  1469. X            case ASCII_SETUP+6:
  1470. X                p.timer = atoi(str);
  1471. X                break;
  1472. X            case ASCII_SETUP+7:
  1473. X                p.cr_dn = str_dup(str);
  1474. X                break;
  1475. X            case ASCII_SETUP+8:
  1476. X                p.lf_dn = str_dup(str);
  1477. X                break;
  1478. X
  1479. X                    /* used in d_revise() */
  1480. X            case LD_CODES:
  1481. X                p.ld_plus = str_dup(str);
  1482. X                break;
  1483. X            case LD_CODES+1:
  1484. X                p.ld_minus = str_dup(str);
  1485. X                break;
  1486. X            case LD_CODES+2:
  1487. X                p.ld_at = str_dup(str);
  1488. X                break;
  1489. X            case LD_CODES+3:
  1490. X                p.ld_pound = str_dup(str);
  1491. X                break;
  1492. X
  1493. X                    /* used in macro() */
  1494. X            case MACROS:
  1495. X                p.mac_1 = str_dup(str);
  1496. X                break;
  1497. X            case MACROS+1:
  1498. X                p.mac_2 = str_dup(str);
  1499. X                break;
  1500. X            case MACROS+2:
  1501. X                p.mac_3 = str_dup(str);
  1502. X                break;
  1503. X            case MACROS+3:
  1504. X                p.mac_4 = str_dup(str);
  1505. X                break;
  1506. X            case MACROS+4:
  1507. X                p.mac_5 = str_dup(str);
  1508. X                break;
  1509. X            case MACROS+5:
  1510. X                p.mac_6 = str_dup(str);
  1511. X                break;
  1512. X            case MACROS+6:
  1513. X                p.mac_7 = str_dup(str);
  1514. X                break;
  1515. X            case MACROS+7:
  1516. X                p.mac_8 = str_dup(str);
  1517. X                break;
  1518. X            case MACROS+8:
  1519. X                p.mac_9 = str_dup(str);
  1520. X                break;
  1521. X            case MACROS+9:
  1522. X                p.mac_0 = str_dup(str);
  1523. X                break;
  1524. X        }
  1525. X    }
  1526. X    fclose(fp);
  1527. X    if (oops) {
  1528. X        sprintf(buf, "Parameter file \"%s\"", p.p_path);
  1529. X        error_win(1, buf, message);
  1530. X    }
  1531. X    return(&p);
  1532. X}
  1533. X
  1534. X/*
  1535. X * Write the updated param structure to disk.  The values in memory should
  1536. X * have already been "purified".  Later, we'll update only the entries that
  1537. X * have been explicitly asked for.  A non-zero return code means non-fatal
  1538. X * error.
  1539. X */
  1540. X
  1541. Xint
  1542. Xup_param()
  1543. X{
  1544. X    FILE *fp, *my_fopen();
  1545. X    char buf[80];
  1546. X    void error_win();
  1547. X                    /* open for write */
  1548. X    if (!(fp = my_fopen(param->p_path, "w"))) {
  1549. X        sprintf(buf, "\"%s\"", param->p_path);
  1550. X        error_win(0, "No write permission on parameter file", buf);
  1551. X        return(1);
  1552. X    }
  1553. X
  1554. X    fprintf(fp, "D_BAUD=%d\n", param->d_baud);
  1555. X    fprintf(fp, "D_PARITY=%c\n", param->d_parity);
  1556. X    fprintf(fp, "D_DBITS=%d\n", param->d_dbits);
  1557. X    fprintf(fp, "D_SBITS=%d\n", param->d_sbits);
  1558. X    fprintf(fp, "HOT=%d\n", param->hot);
  1559. X    fprintf(fp, "ASCII_HOT=%s\n", param->ascii_hot);
  1560. X    fprintf(fp, "D_DUPLEX=%s\n", param->d_duplex);
  1561. X    fprintf(fp, "FLOW=%s\n", param->flow);
  1562. X    fprintf(fp, "CR_IN=%s\n", param->cr_in);
  1563. X    fprintf(fp, "CR_OUT=%s\n", param->cr_out);
  1564. X    fprintf(fp, "LOGFILE=%s\n", param->logfile);
  1565. X    fprintf(fp, "DUMPFILE=%s\n", param->dumpfile);
  1566. X    fprintf(fp, "STRIP=%s\n", param->strip);
  1567. X    fprintf(fp, "PAUSE_CHAR=%c\n", param->pause_char);
  1568. X    fprintf(fp, "CR_CHAR=%c\n", param->cr_char);
  1569. X    fprintf(fp, "CTRL_CHAR=%c\n", param->ctrl_char);
  1570. X    fprintf(fp, "ESC_CHAR=%c\n", param->esc_char);
  1571. X    fprintf(fp, "BRK_CHAR=%c\n", param->brk_char);
  1572. X    fprintf(fp, "ABORT=%s\n", param->abort);
  1573. X    fprintf(fp, "C_DELAY=%d\n", param->c_delay);
  1574. X    fprintf(fp, "R_DELAY=%d\n", param->r_delay);
  1575. X    fprintf(fp, "LECHO=%s\n", param->lecho);
  1576. X    fprintf(fp, "EXPAND=%s\n", param->expand);
  1577. X    fprintf(fp, "CR_DELAY=%d\n", param->cr_delay);
  1578. X    fprintf(fp, "PACE=%s\n", param->pace);
  1579. X    fprintf(fp, "CR_UP=%s\n", param->cr_up);
  1580. X    fprintf(fp, "LF_UP=%s\n", param->lf_up);
  1581. X    fprintf(fp, "TIMER=%d\n", param->timer);
  1582. X    fprintf(fp, "CR_DN=%s\n", param->cr_dn);
  1583. X    fprintf(fp, "LF_DN=%s\n", param->lf_dn);
  1584. X    fprintf(fp, "LD_PLUS=%s\n", param->ld_plus);
  1585. X    fprintf(fp, "LD_MINUS=%s\n", param->ld_minus);
  1586. X    fprintf(fp, "LD_AT=%s\n", param->ld_at);
  1587. X    fprintf(fp, "LD_POUND=%s\n", param->ld_pound);
  1588. X    fprintf(fp, "MAC_1=%s\n", param->mac_1);
  1589. X    fprintf(fp, "MAC_2=%s\n", param->mac_2);
  1590. X    fprintf(fp, "MAC_3=%s\n", param->mac_3);
  1591. X    fprintf(fp, "MAC_4=%s\n", param->mac_4);
  1592. X    fprintf(fp, "MAC_5=%s\n", param->mac_5);
  1593. X    fprintf(fp, "MAC_6=%s\n", param->mac_6);
  1594. X    fprintf(fp, "MAC_7=%s\n", param->mac_7);
  1595. X    fprintf(fp, "MAC_8=%s\n", param->mac_8);
  1596. X    fprintf(fp, "MAC_9=%s\n", param->mac_9);
  1597. X    fprintf(fp, "MAC_0=%s\n", param->mac_0);
  1598. X
  1599. X    fclose(fp);
  1600. X    return(0);
  1601. X}
  1602. SHAR_EOF
  1603. if test 7337 -ne "`wc -c < 'p_lib.c'`"
  1604. then
  1605.     echo shar: "error transmitting 'p_lib.c'" '(should have been 7337 characters)'
  1606. fi
  1607. fi
  1608. echo shar: "extracting 'param.h'" '(2757 characters)'
  1609. if test -f 'param.h'
  1610. then
  1611.     echo shar: "will not over-write existing file 'param.h'"
  1612. else
  1613. sed 's/^X//' << \SHAR_EOF > 'param.h'
  1614. X/*
  1615. X * The standard Pcomm parameters.  Everything can be altered by using one
  1616. X * of Pcomm's menus.  Although editing by hand is not encouraged, the
  1617. X * pcomm.param file is just an ASCII file.
  1618. X */
  1619. X
  1620. X#define MAX_CDELAY    120
  1621. X#define MIN_CDELAY    10
  1622. X#define MAX_PAUSE    120
  1623. X#define MIN_PAUSE    1
  1624. X#define MAX_TIMER    20
  1625. X#define MIN_TIMER    2
  1626. X
  1627. X#define NUM_PARAM    44
  1628. X#define LINE_SET    0
  1629. X#define TERM_SETUP    4
  1630. X#define GEN_SETUP    10
  1631. X#define DELAY_TIMES    19
  1632. X#define ASCII_SETUP    21
  1633. X#define LD_CODES    30
  1634. X#define MACROS        34
  1635. X
  1636. Xstruct PARAM {
  1637. X                /* 0-3 used in ls_menu() */
  1638. X    int    d_baud;            /* default baud rate */
  1639. X    char    d_parity;        /* default parity */
  1640. X    int    d_dbits;        /* default data bits */
  1641. X    int    d_sbits;        /* default stop bits */
  1642. X
  1643. X                /* 4-9 used in term_setup() */
  1644. X    int    hot;            /* the decimal code for the hot key */
  1645. X    char    *ascii_hot;        /* ascii representation of hot key */
  1646. X    char    *d_duplex;        /* default duplex */
  1647. X    char    *flow;            /* flow control */
  1648. X    char    *cr_in;            /* send as carriage return */
  1649. X    char    *cr_out;        /* receive carriage return as */
  1650. X
  1651. X                /* 10-18 used in gen_setup() */
  1652. X    char    *logfile;        /* default log file */
  1653. X    char    *dumpfile;        /* default screen dump file */
  1654. X    char    *strip;            /* strip high bit (translate table) */
  1655. X    char    pause_char;        /* pause char synonym */
  1656. X    char    cr_char;        /* carriage return char synonym */
  1657. X    char    ctrl_char;        /* ctrl char synonym */
  1658. X    char    esc_char;        /* escape char synonym */
  1659. X    char    brk_char;        /* modem break synonym */
  1660. X    char    *abort;            /* destination of aborted downloads */
  1661. X
  1662. X                /* 19-20 used in gen_setup() & delay_times() */
  1663. X    int    c_delay;        /* connect delay time */
  1664. X    int    r_delay;        /* redial delay time */
  1665. X
  1666. X                /* 21-29 used in axfer_setup() */
  1667. X    char    *lecho;            /* echo locally? */
  1668. X    char    *expand;        /* expand blank lines? */
  1669. X    int    cr_delay;        /* carriage return delay (ms) */
  1670. X    char    *pace;            /* pace the output? */
  1671. X    char    *cr_up;            /* send carriage return as */
  1672. X    char    *lf_up;            /* send line feed as */
  1673. X    int    timer;            /* transfer timeout */
  1674. X    char    *cr_dn;            /* receive carriage return as */
  1675. X    char    *lf_dn;            /* receive line feed as */
  1676. X
  1677. X                /* 30-33 used in d_revise() */
  1678. X    char    *ld_plus;        /* + long distance code */
  1679. X    char    *ld_minus;        /* - long distance code */
  1680. X    char    *ld_at;            /* @ long distance code */
  1681. X    char    *ld_pound;        /* # long distance code */
  1682. X
  1683. X                /* 34-43 used in macro() */
  1684. X    char    *mac_1;            /* shifted 1 macro */
  1685. X    char    *mac_2;            /* shifted 2 macro */
  1686. X    char    *mac_3;            /* shifted 3 macro */
  1687. X    char    *mac_4;            /* shifted 4 macro */
  1688. X    char    *mac_5;            /* shifted 5 macro */
  1689. X    char    *mac_6;            /* shifted 6 macro */
  1690. X    char    *mac_7;            /* shifted 7 macro */
  1691. X    char    *mac_8;            /* shifted 8 macro */
  1692. X    char    *mac_9;            /* shifted 9 macro */
  1693. X    char    *mac_0;            /* shifted 0 macro */
  1694. X
  1695. X    char    *p_path;        /* path to the pcomm.param file */
  1696. X};
  1697. X
  1698. X#ifndef MAIN
  1699. Xextern struct PARAM *param;
  1700. X#endif /* MAIN */
  1701. SHAR_EOF
  1702. if test 2757 -ne "`wc -c < 'param.h'`"
  1703. then
  1704.     echo shar: "error transmitting 'param.h'" '(should have been 2757 characters)'
  1705. fi
  1706. fi
  1707. echo shar: "extracting 'passthru.c'" '(2489 characters)'
  1708. if test -f 'passthru.c'
  1709. then
  1710.     echo shar: "will not over-write existing file 'passthru.c'"
  1711. else
  1712. sed 's/^X//' << \SHAR_EOF > 'passthru.c'
  1713. X/*
  1714. X * A transparent "pass-thru" mode, designed to allow binary transfers
  1715. X * between 3 machines (with the middle machine in the pass-thru mode).
  1716. X * A non-zero return code means the input routine should be restarted.
  1717. X */
  1718. X
  1719. X#include <stdio.h>
  1720. X#include <signal.h>
  1721. X#include <curses.h>
  1722. X#include "config.h"
  1723. X#include "misc.h"
  1724. X
  1725. X#ifdef BSD
  1726. X#include <setjmp.h>
  1727. Xjmp_buf cp_buf;
  1728. X#endif /* BSD */
  1729. X
  1730. Xint
  1731. Xpass_thru()
  1732. X{
  1733. X    extern int fd;
  1734. X    WINDOW *pt_win, *newwin();
  1735. X    int num;
  1736. X    void cpio(), error_win();
  1737. X
  1738. X    pt_win = newwin(5, 70, 5, 5);
  1739. X
  1740. X    mvwaddstr(pt_win, 2, 4, "Enter the expiration time (5-60 sec): ");
  1741. X    box(pt_win, VERT, HORZ);
  1742. X
  1743. X    mvwattrstr(pt_win, 0, 3, A_BOLD, " Pass Through Mode ");
  1744. X    wmove(pt_win, 2, 43);
  1745. X    wrefresh(pt_win);
  1746. X                    /* get the answer */
  1747. X    while ((num = get_num(pt_win, 2)) != -1) {
  1748. X                    /* out of bounds */
  1749. X        if (num < 5 || num > 60) {
  1750. X            beep();
  1751. X            clear_line(pt_win, 2, 43, TRUE);
  1752. X            wmove(pt_win, 2, 43);
  1753. X            wrefresh(pt_win);
  1754. X        }
  1755. X        else {
  1756. X            werase(pt_win);
  1757. X            wrefresh(pt_win);
  1758. X            delwin(pt_win);
  1759. X
  1760. X            if (fd == -1) {
  1761. X                error_win(0, "Not currently connected to any host", "");
  1762. X                return(0);
  1763. X            }
  1764. X
  1765. X            touchwin(stdscr);
  1766. X            refresh();
  1767. X
  1768. X            cpio((unsigned int) num);
  1769. X            return(1);
  1770. X        }
  1771. X    }
  1772. X    if (fd == -1) {
  1773. X        werase(pt_win);
  1774. X        wrefresh(pt_win);
  1775. X    }
  1776. X    delwin(pt_win);
  1777. X    return(0);
  1778. X}
  1779. X
  1780. X/*
  1781. X * Copy the stdin to the TTYout and copy the TTYin to the stdout.  Uses
  1782. X * multi character reads.  I'm not too concerned about the excess baggage
  1783. X * caused by the entire image being forked... this feature won't be used
  1784. X * that often.
  1785. X */
  1786. X
  1787. Xstatic int cp_flag;
  1788. X
  1789. Xstatic void
  1790. Xcpio(num)
  1791. Xunsigned int num;
  1792. X{
  1793. X    extern int fd;
  1794. X    int cpid, n, cp_force();
  1795. X    char buf[CLIST_SIZ];
  1796. X    unsigned int alarm(), sleep();
  1797. X    void line_set(), xmodem_mode(), input_off();
  1798. X
  1799. X                    /* out of curses mode */
  1800. X    resetterm();
  1801. X
  1802. X    input_off();
  1803. X    xmodem_mode(0);
  1804. X    xmodem_mode(fd);
  1805. X
  1806. X                    /* copy the TTYin to stdout */
  1807. X    if (!(cpid = fork())) {
  1808. X        while (1) {
  1809. X            n = read(fd, buf, CLIST_SIZ);
  1810. X            write(1, buf, n);
  1811. X        }
  1812. X    }
  1813. X
  1814. X    cp_flag = 0;
  1815. X    signal(SIGALRM, cp_force);
  1816. X                    /* copy the stdin to TTYout */
  1817. X    while (1) {
  1818. X        alarm(num);
  1819. X#ifdef BSD
  1820. X        if (setjmp(cp_buf))
  1821. X            break;
  1822. X#endif /* BSD */
  1823. X        n = read(0, buf, CLIST_SIZ);
  1824. X        if (cp_flag)
  1825. X            break;
  1826. X        write(fd, buf, n);
  1827. X    }
  1828. X    kill(cpid, SIGKILL);
  1829. X                    /* back to curses mode */
  1830. X    sleep(1);
  1831. X    fixterm();
  1832. X    beep();
  1833. X    line_set();
  1834. X    clearok(curscr, TRUE);
  1835. X    return;
  1836. X}
  1837. X
  1838. X/* ARGSUSED */
  1839. Xstatic int
  1840. Xcp_force(dummy)
  1841. X{
  1842. X#ifdef BSD
  1843. X    longjmp(cp_buf, 1);
  1844. X#else /* BSD */
  1845. X    signal(SIGALRM, cp_force);
  1846. X    cp_flag = 1;
  1847. X#endif /* BSD */
  1848. X}
  1849. SHAR_EOF
  1850. if test 2489 -ne "`wc -c < 'passthru.c'`"
  1851. then
  1852.     echo shar: "error transmitting 'passthru.c'" '(should have been 2489 characters)'
  1853. fi
  1854. fi
  1855. echo shar: "extracting 'pexit.c'" '(2579 characters)'
  1856. if test -f 'pexit.c'
  1857. then
  1858.     echo shar: "will not over-write existing file 'pexit.c'"
  1859. else
  1860. sed 's/^X//' << \SHAR_EOF > 'pexit.c'
  1861. X/*
  1862. X * Exit Pcomm.  A user requested abort.  There are a lot of things to do
  1863. X * before we exit!
  1864. X */
  1865. X
  1866. X#include <stdio.h>
  1867. X#include <curses.h>
  1868. X#include "config.h"
  1869. X#include "dial_dir.h"
  1870. X#include "misc.h"
  1871. X#include "param.h"
  1872. X#include "status.h"
  1873. X
  1874. X#ifdef SHAREDMEM
  1875. X#include <sys/types.h>
  1876. X#include <sys/ipc.h>
  1877. X#include <sys/shm.h>
  1878. X#endif /* SHAREDMEM */
  1879. X
  1880. Xvoid
  1881. Xpexit()
  1882. X{
  1883. X    extern int fd;
  1884. X    WINDOW *ex_win, *newwin();
  1885. X    void cleanup(), st_line();
  1886. X
  1887. X    ex_win = newwin(5, 33, 3, 7);
  1888. X
  1889. X    box(ex_win, VERT, HORZ);
  1890. X    mvwattrstr(ex_win, 0, 3, A_BOLD, " Exit ");
  1891. X    if (yes_prompt(ex_win, 2, 4, A_BLINK, "Exit to Unix")) {
  1892. X        st_line("   exiting");
  1893. X        cleanup(0);
  1894. X    }
  1895. X    if (fd == -1) {
  1896. X        werase(ex_win);
  1897. X        wrefresh(ex_win);
  1898. X    }
  1899. X    delwin(ex_win);
  1900. X    return;
  1901. X}
  1902. X
  1903. X/*
  1904. X * Do the clean up detail before we exit.  Only the status structure
  1905. X * is guaranteed to exit.
  1906. X */
  1907. X
  1908. Xvoid
  1909. Xcleanup(val)
  1910. Xint val;
  1911. X{
  1912. X    extern int msg_status;
  1913. X    void release_port(), input_off(), exit();
  1914. X    char *ttyname();
  1915. X#ifdef SHAREDMEM
  1916. X    extern int shm_id;
  1917. X    void perror();
  1918. X#endif /* SHAREDMEM */
  1919. X                    /* kill the input routine */
  1920. X    input_off();
  1921. X                    /* release the port */
  1922. X    release_port(QUIET);
  1923. X                    /* zap the virtual screen */
  1924. X#ifdef SHAREDMEM
  1925. X    if (shmdt((char *) status) < 0)
  1926. X        perror("shmdt");
  1927. X    if (shmctl(shm_id, IPC_RMID, (struct shmid_ds *) NULL) < 0)
  1928. X        perror("shmctl");
  1929. X#else /* SHAREDMEM */
  1930. X    unlink(status->vs_path);
  1931. X#endif /* SHAREDMEM */
  1932. X
  1933. X    /*
  1934. X     * If we die an un-natural death (such as a SIGHUP on the loss of
  1935. X     * the controlling terminal) we won't have a terminal to mess with.
  1936. X     */
  1937. X    if (isatty(0)) {
  1938. X        touchwin(stdscr);
  1939. X        clear();
  1940. X        refresh();
  1941. X        endwin();
  1942. X                    /* return the TTY chmod */
  1943. X        chmod(ttyname(0), msg_status);
  1944. X    }
  1945. X    exit(val);
  1946. X}
  1947. X
  1948. X/*
  1949. X * Open a window to display an error message.  Handles both fatal and
  1950. X * non-fatal errors
  1951. X */
  1952. X
  1953. Xvoid
  1954. Xerror_win(code, line_one, line_two)
  1955. Xint code;
  1956. Xchar *line_one, *line_two;
  1957. X{
  1958. X    WINDOW *e_win, *newwin();
  1959. X    void cleanup(), st_line();
  1960. X
  1961. X                    /* make sure we're in curses mode */
  1962. X    fixterm();
  1963. X    e_win = newwin(7, 70, 9, 5);
  1964. X                    /* display the nasty note */
  1965. X    mvwaddstr(e_win, 2, 4, line_one);
  1966. X    mvwaddstr(e_win, 3, 4, line_two);
  1967. X    box(e_win, VERT, HORZ);
  1968. X
  1969. X    if (code) {
  1970. X        mvwattrstr(e_win, 0, 4, A_BOLD, " Error ");
  1971. X        mvwattrstr(e_win, 5, 24, A_BLINK, "Press any key to exit");
  1972. X        wmove(e_win, 5, 46);
  1973. X    }
  1974. X    else {
  1975. X        mvwattrstr(e_win, 0, 4, A_BOLD, " Warning ");
  1976. X        mvwattrstr(e_win, 5, 22, A_BLINK, "Press any key to continue");
  1977. X        wmove(e_win, 5, 48);
  1978. X    }
  1979. X    beep();
  1980. X    wrefresh(e_win);
  1981. X
  1982. X    wgetch(e_win);
  1983. X    werase(e_win);
  1984. X    wrefresh(e_win);
  1985. X    delwin(e_win);
  1986. X
  1987. X    if (code) {
  1988. X        st_line("   exiting");
  1989. X        cleanup(code);
  1990. X    }
  1991. X    return;
  1992. X}
  1993. SHAR_EOF
  1994. if test 2579 -ne "`wc -c < 'pexit.c'`"
  1995. then
  1996.     echo shar: "error transmitting 'pexit.c'" '(should have been 2579 characters)'
  1997. fi
  1998. fi
  1999. echo shar: "extracting 'port.c'" '(10197 characters)'
  2000. if test -f 'port.c'
  2001. then
  2002.     echo shar: "will not over-write existing file 'port.c'"
  2003. else
  2004. sed 's/^X//' << \SHAR_EOF > 'port.c'
  2005. X/*
  2006. X * Routines to get or release a TTY port.
  2007. X */
  2008. X
  2009. X#define MAX_PID    30000
  2010. X#define TRUE    1
  2011. X#define FALSE    0
  2012. X
  2013. X#include <stdio.h>
  2014. X#include <fcntl.h>
  2015. X#include <errno.h>
  2016. X#include "config.h"
  2017. X#include "dial_dir.h"
  2018. X#include "modem.h"
  2019. X
  2020. X#ifdef BSD
  2021. X#include <sys/file.h>
  2022. X#endif /* BSD */
  2023. X
  2024. X#ifdef UNIXPC
  2025. X#include <sys/phone.h>
  2026. X#endif /* UNIXPC */
  2027. X
  2028. X#ifdef XENIX_LOCKS
  2029. X#include <ctype.h>
  2030. X#endif /* XENIX_LOCKS */
  2031. X
  2032. Xstatic int getty_status = 0;
  2033. Xstatic char *lock_path = NULL;
  2034. X/*
  2035. X * Finds a free (or requested) serial port.  Creates a lock file to hold
  2036. X * for our use.  Loads the modem database.  A non-zero return code means
  2037. X * all ports (or the requested port) are busy.
  2038. X */
  2039. X
  2040. Xint
  2041. Xget_port()
  2042. X{
  2043. X    extern int fd;
  2044. X    register int i;
  2045. X    int j, k, lfd, list[NUM_TTY], cmask, tbaud, is_dev, progpid;
  2046. X    char file[80], buf[80], message[80], *str_rep(), *last_c;
  2047. X    unsigned int sleep();
  2048. X    void error_win(), line_set(), release_port(), send_str();
  2049. X
  2050. X    is_dev = chk_script(dir->script[dir->d_cur]);
  2051. X    /*
  2052. X     * If you already have a port, see if it is good enough for the
  2053. X     * current request.
  2054. X     */
  2055. X#ifdef KEEP_PORT
  2056. X    if (fd != -1) {
  2057. X        if (!strcmp(dir->script[dir->d_cur], modem->tty[modem->t_cur])
  2058. X         || (!is_dev && ck_speed(modem->t_cur, dir->baud[dir->d_cur]))){
  2059. X            /*
  2060. X             * Reset the line because the baud rate (or other
  2061. X             * parameters) may have changed.
  2062. X             */
  2063. X            line_set();
  2064. X            return(0);
  2065. X        }
  2066. X    }
  2067. X#endif /* KEEP_PORT */
  2068. X
  2069. X    release_port(VERBOSE);
  2070. X
  2071. X    list[0] = -1;
  2072. X    /*
  2073. X     * See if you want a specific TTY port.  If the script field in the
  2074. X     * dialing directory is a valid device name, then use that TTY.
  2075. X     */
  2076. X    if (is_dev) {
  2077. X        for (i=0; i<modem->t_entries; i++) {
  2078. X                    /* and it exists in modem database */
  2079. X            if (!strcmp(dir->script[dir->d_cur], modem->tty[i])) {
  2080. X                list[0] = i;
  2081. X                list[1] = -1;
  2082. X                break;
  2083. X            }
  2084. X        }
  2085. X                    /* oops... we don't know that port */
  2086. X        if (list[0] == -1) {
  2087. X            sprintf(message, "Device \"%s\" in the script field doesn't exist in", dir->script[dir->d_cur]);
  2088. X            sprintf(buf, "modem/TTY database \"%s\"", modem->m_path);
  2089. X            error_win(0, message, buf);
  2090. X        }
  2091. X    }
  2092. X
  2093. X    /*
  2094. X     * Create a list of acceptable TTYs.  It searches the modem database
  2095. X     * for the requested baud rate.
  2096. X     */
  2097. X    k = 0;
  2098. X    if (list[0] == -1) {
  2099. X        for (i=0; i<modem->t_entries; i++) {
  2100. X                    /* skip ports with no modems */
  2101. X            if (!strcmp(modem->tname[i], "DIRECT"))
  2102. X                continue;
  2103. X
  2104. X                    /* can handle requested baud rate? */
  2105. X            if (ck_speed(i, dir->baud[dir->d_cur]))
  2106. X                list[k++] = i;
  2107. X        }
  2108. X                    /* the end of list marker */
  2109. X        list[k] = -1;
  2110. X    }
  2111. X                    /* empty list? */
  2112. X    if (list[0] == -1) {
  2113. X        sprintf(message, "No modem at a %d baud rating exists in the", dir->baud[dir->d_cur]);
  2114. X        sprintf(buf, "modem database \"%s\"", modem->m_path);
  2115. X        error_win(0, message, buf);
  2116. X        return(1);
  2117. X    }
  2118. X                    /* check the list for a free port */
  2119. X    i = 0;
  2120. X    while (list[i] != -1) {
  2121. X                    /* create a lock file name */
  2122. X        sprintf(file, "%s/LCK..%s", LOCK_DIR, modem->tty[list[i]]);
  2123. X
  2124. X#ifdef XENIX_LOCKS
  2125. X        last_c = file + strlen(file)-1;
  2126. X        if (isuuper(*last_c))
  2127. X            *last_c = tolower(*last_c);
  2128. X#endif /* XENIX_LOCKS */
  2129. X
  2130. X#ifdef DEBUG
  2131. X        fprintf(stderr, "get_port: checking '/dev/%s'\n", modem->tty[list[i]]);
  2132. X#endif /* DEBUG */
  2133. X
  2134. X                    /* no lock exists or it is dead */
  2135. X        if (checklock(file)) {
  2136. X            getty_status = set_getty(modem->tty[list[i]], FALSE);
  2137. X
  2138. X            cmask = umask(0);
  2139. X            if ((lfd = open(file, O_CREAT|O_EXCL|O_WRONLY, 0666)) < 0) {
  2140. X                if (getty_status)
  2141. X                    set_getty(modem->tty[list[i]], TRUE);
  2142. X                sprintf(buf, "\"%s\"", file);
  2143. X                error_win(1, "Can't create the lockfile", buf);
  2144. X            }
  2145. X            umask(cmask);
  2146. X#ifdef ASCII_PID
  2147. X            sprintf(buf, "%10d\n", getpid());
  2148. X            write(lfd, buf, 11);
  2149. X#else /* ASCII_PID */
  2150. X            progpid = getpid();
  2151. X            write(lfd, (char *) &progpid, sizeof(int));
  2152. X#endif /* ASCII_PID */
  2153. X            close(lfd);
  2154. X                    /* store the new values */
  2155. X            lock_path = str_rep(lock_path, file);
  2156. X            modem->t_cur = list[i];
  2157. X
  2158. X                    /* open the device (ignore DCD) */
  2159. X            sprintf(buf, "/dev/%s", modem->tty[modem->t_cur]);
  2160. X            if ((fd = open(buf, O_RDWR|O_NDELAY)) < 0) {
  2161. X                if (getty_status)
  2162. X                    set_getty(modem->tty[modem->t_cur], TRUE);
  2163. X                sprintf(file, "Can't open port \"%s\" for read and write", buf);
  2164. X                error_win(1, file, "");
  2165. X            }
  2166. X                    /* change line settings */
  2167. X            line_set();
  2168. X                    /* ...just to be sure */
  2169. X            close(open(buf, O_RDWR));
  2170. X
  2171. X                    /* turn off the O_NDELAY setting */
  2172. X            tty_noblock(fd, FALSE);
  2173. X
  2174. X                    /* load the modem data base */
  2175. X            modem->m_cur = -1;
  2176. X            for (j=0; j<modem->m_entries; j++) {
  2177. X                if (!strcmp(modem->tname[modem->t_cur], modem->mname[j])) {
  2178. X                    modem->m_cur = j;
  2179. X                    break;
  2180. X                }
  2181. X            }
  2182. X            if (modem->m_cur == -1) {
  2183. X                sprintf(buf, "Modem name \"%s\" in TTY database",
  2184. X                 modem->tname[modem->t_cur]);
  2185. X                error_win(1, buf, "does not exist in modem database");
  2186. X            }
  2187. X                    /* initialize the modem */
  2188. X            if (modem->init_sp[modem->t_cur]) {
  2189. X                tbaud = dir->baud[dir->d_cur];
  2190. X                dir->baud[dir->d_cur] = modem->init_sp[modem->t_cur];
  2191. X                line_set();
  2192. X                send_str(modem->init[modem->m_cur], SLOW);
  2193. X                dir->baud[dir->d_cur] = tbaud;
  2194. X            }
  2195. X            else
  2196. X                send_str(modem->init[modem->m_cur], SLOW);
  2197. X            sleep(1);
  2198. X            return(0);
  2199. X        }
  2200. X        i++;
  2201. X    }
  2202. X    error_win(0, "All ports are busy now, try again later", "");
  2203. X    return(1);
  2204. X}
  2205. X
  2206. X/*
  2207. X * Release the port.  Closes the file descriptor and removes the
  2208. X * lock file
  2209. X */
  2210. X
  2211. Xvoid
  2212. Xrelease_port(verbose)
  2213. Xint verbose;
  2214. X{
  2215. X    extern int fd;
  2216. X    extern char *null_ptr;
  2217. X    char buf[80];
  2218. X    void free_ptr(), hang_up();
  2219. X
  2220. X    /*
  2221. X     * The modem structure can't be guaranteed to exist yet.  For example,
  2222. X     * an error in reading one of the other support files would cause
  2223. X     * this routine to be used before the MODEM structure gets allocated.
  2224. X     */
  2225. X    if (modem == NULL)
  2226. X        return;
  2227. X                    /* close the port */
  2228. X    if (fd != -1) {
  2229. X        tty_flush(fd, 2);
  2230. X        /*
  2231. X         * Since HUPCL is set, the close() should drop the DTR and
  2232. X         * hang up the modem (provided you've got the modem to
  2233. X         * respond to DTR).  Since this is not guaranteed, we send
  2234. X         * the hang_up string first.
  2235. X         */
  2236. X        hang_up(verbose);
  2237. X        close(fd);
  2238. X    }
  2239. X                    /* remove the lock */
  2240. X    if (lock_path != NULL && *lock_path != '\0') {
  2241. X        if (unlink(lock_path)) {
  2242. X            sprintf(buf, "\"%s\"", lock_path);
  2243. X            error_win(0, "Can't remove the lock file", buf);
  2244. X        }
  2245. X        free_ptr(lock_path);
  2246. X        lock_path = null_ptr;
  2247. X    }
  2248. X                    /* turn the getty back on? */
  2249. X    if (getty_status && modem->t_cur != -1)
  2250. X        set_getty(modem->tty[modem->t_cur], TRUE);
  2251. X                    /* clean up the structure */
  2252. X    fd = -1;
  2253. X    modem->m_cur = -1;
  2254. X    modem->t_cur = -1;
  2255. X    return;
  2256. X}
  2257. X
  2258. X/*
  2259. X * Turn the /etc/getty on or off for the specified port.  A non-zero return
  2260. X * code means that the getty was on.  Systems with uugetty() or dedicated
  2261. X * dialout ports won't need this routine.
  2262. X */
  2263. X
  2264. X/* ARGSUSED */
  2265. Xstatic int
  2266. Xset_getty(tty, on)
  2267. Xchar *tty;
  2268. Xint on;
  2269. X{
  2270. X#ifdef UNIXPC
  2271. X    int i, ret_code;
  2272. X    char buf[40];
  2273. X    unsigned int sleep();
  2274. X                    /* the last three characters */
  2275. X    i = strlen(tty) -3;
  2276. X
  2277. X    ret_code = 0;
  2278. X    if (on) {
  2279. X        sprintf(buf, "setgetty %s 1", tty+i);
  2280. X        system(buf);
  2281. X    }
  2282. X    else {
  2283. X        sprintf(buf, "setgetty %s 0", tty+i);
  2284. X        if (system(buf) == 512)
  2285. X            ret_code++;
  2286. X        sleep(1);
  2287. X    }
  2288. X    return(ret_code);
  2289. X#else /* UNIXPC */
  2290. X    /*
  2291. X     * If you don't have one of these cute little routines, you
  2292. X     * might wanna write one.  It should check for an existing lock
  2293. X     * file, edit the /etc/inittab file, and issue an init -q.
  2294. X     * The return code should tell if there was a getty or not.
  2295. X     * Obviously the program would be suid to root.
  2296. X     */
  2297. X    return(0);
  2298. X#endif /* UNIXPC */
  2299. X}
  2300. X
  2301. X/*
  2302. X * Check the lock file for a valid pid value.  Error conditions such
  2303. X * as not being able to open the lock file or not being able to interpret
  2304. X * the contents of the lock file cause the code to assume that the lock
  2305. X * file is valid.  Let the user worry about weird special cases.  A 
  2306. X * non-zero return code means the lock is dead or doesn't exist.
  2307. X */
  2308. X
  2309. Xstatic int
  2310. Xchecklock(lockfile)
  2311. Xchar *lockfile;
  2312. X{
  2313. X    extern int errno;
  2314. X    int lfd, lckpid, n;
  2315. X    char buf[40];
  2316. X                    /* doesn't exist */
  2317. X    if (access(lockfile, 0))
  2318. X        return(1);
  2319. X                    /* can't open the lock file */
  2320. X    if ((lfd = open(lockfile, 0)) < 0)
  2321. X        return(0);
  2322. X
  2323. X#ifdef ASCII_PID
  2324. X    if ((n = read(lfd, buf, 40)) <= 0) {
  2325. X        close(lfd);
  2326. X        return(0);
  2327. X    }
  2328. X    close(lfd);
  2329. X    buf[n--] = '\0';
  2330. X    lckpid = atoi(buf);
  2331. X#else /* ASCII_PID */
  2332. X    if (read(lfd, (char *) &lckpid, sizeof(int)) != sizeof(int)) {
  2333. X        close(lfd);
  2334. X        return(0);
  2335. X    }
  2336. X    close(lfd);
  2337. X#endif /* ASCII_PID */
  2338. X                    /* invalid pid? */
  2339. X    if (lckpid <= 0 || lckpid > MAX_PID)
  2340. X        return(0);
  2341. X
  2342. X    if ((kill(lckpid, 0) == -1) && (errno == ESRCH)) {
  2343. X        /*
  2344. X         * If the kill was unsuccessful due to an ESRCH error,
  2345. X         * that means the process is no longer active and the
  2346. X         * lock file can be safely removed.
  2347. X         */
  2348. X        unlink(lockfile);
  2349. X        sleep(1);
  2350. X        return(1);
  2351. X    }
  2352. X    /*
  2353. X     * If the kill() was successful, that means the process must
  2354. X     * still be active.
  2355. X     */
  2356. X    return(0);
  2357. X}
  2358. X
  2359. X/*
  2360. X * Check to see if the desired baud rate can be handled by the modem.
  2361. X * Uses the connect strings to make this determination.  The first
  2362. X * argument is the index into the TTY database.  A non-zero return code
  2363. X * means "yes it can".
  2364. X */
  2365. X
  2366. Xstatic int
  2367. Xck_speed(tty, baud)
  2368. Xint tty, baud;
  2369. X{
  2370. X    int i, mod;
  2371. X    char buf[60];
  2372. X                    /* find the modem database */
  2373. X    mod = -1;
  2374. X    for (i=0; i<modem->m_entries; i++) {
  2375. X        if (!strcmp(modem->mname[i], modem->tname[tty])) {
  2376. X            mod = i;
  2377. X            break;
  2378. X        }
  2379. X    }
  2380. X    if (mod == -1) {
  2381. X        sprintf(buf, "Modem name \"%s\" in TTY database", modem->tname[tty]);
  2382. X        error_win(1, buf, "does not exist in modem database");
  2383. X    }
  2384. X
  2385. X#ifdef DEBUG
  2386. X    fprintf(stderr, "ck_speed: checking modem \"%s\" for %d baud\n", modem->mname[mod], baud);
  2387. X#endif /* DEBUG */
  2388. X
  2389. X    switch (baud) {
  2390. X        case 300:
  2391. X            if (*modem->con_3[mod] != '\0')
  2392. X                return(1);
  2393. X            break;
  2394. X        case 1200:
  2395. X            if (*modem->con_12[mod] != '\0')
  2396. X                return(1);
  2397. X            break;
  2398. X        case 2400:
  2399. X            if (*modem->con_24[mod] != '\0')
  2400. X                return(1);
  2401. X            break;
  2402. X        case 4800:
  2403. X            if (*modem->con_48[mod] != '\0')
  2404. X                return(1);
  2405. X            break;
  2406. X        case 9600:
  2407. X            if (*modem->con_96[mod] != '\0')
  2408. X                return(1);
  2409. X            break;
  2410. X        case 19200:
  2411. X            if (*modem->con_192[mod] != '\0')
  2412. X                return(1);
  2413. X            break;
  2414. X    }
  2415. X    return(0);
  2416. X}
  2417. X
  2418. X/*
  2419. X * Check to see if the script field is a valid device name.
  2420. X */
  2421. X
  2422. Xchk_script(script)
  2423. Xchar *script;
  2424. X{
  2425. X    char buf[80], *strcpy(), *strcat();
  2426. X
  2427. X    if (*script == '\0')
  2428. X        return(0);
  2429. X
  2430. X    strcpy(buf, "/dev/");
  2431. X    strcat(buf, script);
  2432. X
  2433. X    if (!access(buf, 0))
  2434. X        return(1);
  2435. X    return(0);
  2436. X}
  2437. SHAR_EOF
  2438. if test 10197 -ne "`wc -c < 'port.c'`"
  2439. then
  2440.     echo shar: "error transmitting 'port.c'" '(should have been 10197 characters)'
  2441. fi
  2442. fi
  2443. exit 0
  2444. #    End of shell archive
  2445.  
  2446.  
  2447.